package com.somiz.reparation;

import java.util.List;

import org.hibernate.Session;

import com.gest.util.Dates;
import com.somiz.main.Control;
import com.somiz.objet.ObjetIdentifiableDaoImpl;

public class ReparationDaoImpl extends ObjetIdentifiableDaoImpl<Reparation>
		implements ReparationDao {

	public Reparation TrouverAvecDateEtArticle(Reparation reparation,
			Session session) {
		Reparation reparationTest = new Reparation();
		List<Reparation> reparations = Control.getReparationDao().charger(
				reparationTest, session);
		for (int i = 0; i < reparations.size(); i++) {
			if (reparation.getArticle().getCode()
					.equals(reparations.get(i).getArticle().getCode())
					&& (Dates.ChangerFormatDateString(
							reparation.getDateRecep(), "dd-MM-yyyy")
							.equals(Dates.ChangerFormatDateString(reparations
									.get(i).getDateRecep(), "dd-MM-yyyy")))) {
				reparation = reparations.get(i);

			}
		}
		return reparation;
	}

	public Long TrouverDernierId(Session session) {
		Long id = new Long(0);
		Reparation reparationTest = new Reparation();
		List<Reparation> reparations = Control.getReparationDao().charger(
				reparationTest, session);
		for (int i = 0; i < reparations.size(); i++) {
			if (reparations.get(i).getId() >= id) {
				id = reparations.get(i).getId();
			}
		}
		return id;
	}
}
